<?php
	include_once("sslib/folder.class.php");
	include_once("sslib/cms/module.class.php");
	
	
	
	
	class Cms 
	{
		private $modules = array();
		function Cms() 
		{
			$this->loadModules();
		}
		function Modules()
		{
			return $this->modules;
		}
		/**
		 * Return module object by class name
		 *
		 * @param string $class_name
		 * @return Module
		 */
		function Module($class_name)
		{
			if(array_key_exists($class_name, $this->modules))
				return $this->modules[$class_name];
			return false;
		}
		
		
		/**
		 * Загрузка модулей
		 *
		 */
		private function loadModules()
		{
			$folder = new Folder('modules');
				
			foreach($folder->Folders() as $f)
			{				
				include_once ($f.'/module.php');
				$basename = basename($f);
				if(class_exists($basename))
				{
					if(array_key_exists($basename,$this->modules)) new Err(__T('module exists'));
					eval('$this->modules["'.$basename.'"] = new '.$basename.'();');
					$this->modules[$basename]->loadParams($f);
				}
			}
			
		}
	}
	
?>